package com.example.demo.listener;

import com.example.demo.message.StreamMessage;
import com.example.demo.procss.MqProcess;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.http.converter.json.GsonBuilderUtils;
import org.springframework.stereotype.Component;


/**
 * @Description
 * @Author liumin0901@sunwayworld.com
 * @Date 2021/4/27 19:27
 */

@Component
@EnableBinding({MqProcess.class})
public class StreamMqListener {

    @StreamListener("input1")
    public void processMyMessage(String message) {
        Gson gson = new Gson();
        StreamMessage streamMessage = gson.fromJson(message, StreamMessage.class);
        assert streamMessage != null;
        System.out.println("接收到消息：" + streamMessage.getBody());
    }
}
